import cn.iocoder.aics.framework.common.pojo.CommonResult;
import cn.iocoder.aics.framework.common.pojo.PageResult;
import cn.iocoder.aics.framework.common.util.object.BeanUtils;
import cn.iocoder.aics.module.member.controller.admin.chatcontext.vo.ChatContextPageReqVO;
import cn.iocoder.aics.module.member.controller.admin.chatcontext.vo.ChatContextRespVO;
import cn.iocoder.aics.module.member.controller.admin.chatcontext.vo.ChatContextSaveReqVO;
import cn.iocoder.aics.module.member.dal.dataobject.chatcontext.ChatContextDO;
import cn.iocoder.aics.module.member.service.chatcontext.ChatContextService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cn.iocoder.aics.framework.common.pojo.CommonResult.success;

@RestController
@RequestMapping("/member/chat-context")
@Validated
public class AppChatContextController {
    @Resource
    private ChatContextService chatContextService;

    @PostMapping("/create")
    @Operation(summary = "创建聊天上下文")
    public CommonResult<Long> createChatContext(@Valid @RequestBody ChatContextSaveReqVO createReqVO) {
        return success(chatContextService.createChatContext(createReqVO));
    }


    @DeleteMapping("/delete")
    @Operation(summary = "删除聊天上下文")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteChatContext(@RequestParam("id") Long id) {
        chatContextService.deleteChatContext(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得聊天上下文")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<ChatContextRespVO> getChatContext(@RequestParam("id") Long id) {
        ChatContextDO chatContext = chatContextService.getChatContext(id);
        return success(BeanUtils.toBean(chatContext, ChatContextRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得聊天上下文分页")
    public CommonResult<PageResult<ChatContextRespVO>> getChatContextPage(@Valid ChatContextPageReqVO pageReqVO) {
        PageResult<ChatContextDO> pageResult = chatContextService.getChatContextPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, ChatContextRespVO.class));
    }
}
